<#-- 
 * description:接口配置界面
 * version: 1.0 
 * author:xiangyu.qi@hand-china.com
 * -->
<#include "../include/header.html">
<body>
<script type="text/javascript">
    var viewModel = Hap.createGridViewModel("#grid");
</script>
<div id="dialogEdit" ></div>
<div id="page-content">
    <div class="pull-left" id="toolbar-btn" style="padding-bottom:10px;">
        <span class="btn btn-primary" style="float:left;margin-right:5px;" onclick="openWindow()"><i class="fa fa-plus-square" style="margin-right:3px;"></i><@spring.message "hap.new"/></span>
        <span data-bind="click:remove"  class="btn btn-danger" style="float:left;"><i class="fa fa-trash-o" style="margin-right:3px;"></i><@spring.message "hap.delete"/></span>
    </div>
    <script>kendo.bind($('#toolbar-btn'), viewModel);</script>
    <div class="pull-right" id="query-form" style="padding-bottom:10px;">
        <input data-role="maskedtextbox" placeholder='<@spring.message "interface.systemcode"/>' type="text" style="width: 150px;float:left;margin-right:5px;" data-bind="value:model.interfaceCode" class="k-textbox">
        <input data-role="maskedtextbox" placeholder='<@spring.message "interface.systemname"/>' type="text" style="width: 150px;float:left;margin-right:5px;" data-bind="value:model.name" class="k-textbox">
        <span class="btn btn-primary" data-bind="click:query" style="width: 80px;float:left;margin-right:5px;" type="submit"><i class="fa fa-search" style="margin-right:3px;"></i><@spring.message "hap.query"/></span>
        <span class="btn btn-default" data-bind="click:reset"  style="width: 80px;float:left;margin-right:5px;" type="button"><i class="fa fa-eraser" style="margin-right:3px;"></i><@spring.message "hap.reset"/></span>
        <div style="clear:both"></div>
    </div>
    <script>kendo.bind($('#query-form'), viewModel);</script>
    <div style="clear: both;">
        <div id="grid"></div>
    </div>
</div>

<script type="text/javascript">

    Hap.initEnterQuery('#query-form', viewModel.query);

    function openWindow(headerId) {
        var url = 'sys_interface_header_edit.html';
        if (headerId) {
            url = url + '?headerId=' + headerId;
        }


        var editWin = Hap.createWindow('#dialogEdit', {
            width: '90%',
            height: 700,
            title: '<@spring.message "hap.edit"/>',
            url: url
        })


        if (parent.autoResizeIframe) {
            parent.autoResizeIframe('${RequestParameters.functionCode!}', 800, function () {
                editWin.center().open();
            })
        } else {
            editWin.center().open();
        }
    }

    var crudServiceBaseUrl = '${base.contextPath}/sys/interface',
        dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: crudServiceBaseUrl + "/queryAllHeader",
                    type: "POST",
                    dataType: "json"
                },
                destroy: {
                    url: crudServiceBaseUrl + "/deleteHeader",
                    contentType: "application/json",
                    type: "POST"
                },
                parameterMap: function (options, type) {
                    if (type !== "read" && options.models) {
                        var datas = Hap.prepareSubmitParameter(options, type);
                        return kendo.stringify(datas);
                    } else if (type === "read") {
                        return Hap.prepareQueryParameter(viewModel.model.toJSON(), options);
                    }
                }
            },
            batch: true,
            serverPaging: true,
            pageSize: 10,
            schema: {
                data: 'rows',
                total: 'total',
                model: {
                    id: "headerId",
                    fields: {
                        interfaceCode: {type: "string"},
                        enableFlag: {
                            defaultValue: 'Y', type: 'boolean', checkedValue: 'Y', uncheckedValue: 'N'
                        },
                        authFlag: {
                            defaultValue: 'Y', type: 'boolean', checkedValue: 'Y', uncheckedValue: 'N'
                        }

                    }
                }
            }
        });
    var grid = $("#grid").kendoGrid({
        dataSource: dataSource,
        navigatable: false,
        dataBound: function(){
            if(parent.autoResizeIframe){
                parent.autoResizeIframe('${RequestParameters.functionCode!}')
            }
        },
        resizable: true,
        scrollable: true,
        selectable : 'multiple, rowbox',
        pageable: {
            pageSizes: [5, 10, 20, 50],
            refresh: true,
            buttonCount: 5
        },
        columns: [
            /* 系统代码 */
            {
                field: "interfaceCode",
                title: '<@spring.message"interface.systemcode"/>',
                width: 120
            },
            /* 系统名称 */
            {
                field: "name",
                title: '<@spring.message"interface.systemname"/>',
                width: 130
            },
            /* 接口类型 */
            {
                field: "interfaceType",
                title: '<@spring.message "interface.interfacetype"/>',
                width: 100
            },
            /* 系统地址 */
            {
                field: "domainUrl",
                title: '<@spring.message "interface.systemurl"/>',
                width: 280
            },

            /* 是否有效 */
            {
                field: "enableFlag",
                headerAttributes: {
                    style  : "text-align: center"
                },
                title: '<@spring.message "interface.enableflag"/>',
                attributes: {style: "text-align:center"},
                width: 100
            },
            /* 是否校验 */
            {
                field: "authFlag",
                headerAttributes: {
                    style  : "text-align: center"
                },
                title: '<@spring.message"interface.authflag"/>',
                attributes: {style: "text-align:center"},
                width: 80
            },
            /* 操作 */ 
             {
                title: '<@spring.message "hap.action"/>',
                width: 100,
                 headerAttributes: {
                     style  : "text-align: center"
                 },
                attributes: {
                    style: "text-align: center"
                  },
                template : function (rowdata) {
                    if (!!rowdata.interfaceCode) {
                        return Hap.createAnchor('<@spring.message "hap.edit"/>',openWindow,rowdata.headerId);
                    }else return ''
                }
            }
        ]
    }).data("kendoGrid");


</script>

</body>
</html>
